package com.itheima.HomeWork;

public class Demo01 {
    public static void main(String[] args) {
        MyThread myThread=new MyThread("售票口1");
        MyThread myThread1=new MyThread("售票口2");
        MyThread myThread2=new MyThread("售票口3");

        myThread.start();
        myThread1.start();
        myThread2.start();
    }
}
class MyThread extends Thread{

    static int ticket=100;
    MyThread(String name){
       super(name);
    }

    @Override
    public void run() {
        while(true){
            synchronized (MyThread.class){
                if(ticket<=0){
                    System.out.println(getName()+"卖光了");
                    break;
                }else{
                    ticket--;
                    System.out.println(getName()+"卖了一张票，还剩"+ticket+"张");
                }
            }
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

        }

    }
}
